package com.lemon.smartsafety.ui.fragment.fire.situation;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.ldzs.recyclerlibrary.view.FullyGridLayoutManager;
import com.ldzs.recyclerlibrary.view.SpacesItemDecoration;
import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.BundleKey;
import com.lemon.smartsafety.entity.safe.company.CompanyBuildingItemCountVo;
import com.lemon.smartsafety.ui.adapter.safe.data.BuildingPositionAdapter;
import com.lemon.smartsafety.ui.adapter.safe.inspection.BuildingPositionForInspectionAdapter;
import com.lemon.smartsafetynew.ui.fragment.base.BaseFragment;
import com.lemon.smartsafety.utils.common.LoggerHelper;

import java.util.List;

import butterknife.Bind;
import kale.adapter.LemonRcvAdapter;

/**
 * 项目名称：workspace
 * 类描述：
 * 创建人：Fargo
 * 创建时间：2016/9/9 16:17
 * 修改人：Fargo
 * 修改时间：2016/9/9 16:17
 * 修改备注：
 */
public class FireInspectionBuildingPositionFragment extends BaseFragment {
    private LoggerHelper loggerHelper = new LoggerHelper(FireInspectionBuildingPositionFragment.class);
    private List<CompanyBuildingItemCountVo> items;


    /** 是否是安全巡查界面过来的 */
    private boolean isSafeInspection = false;

    private int columnNumbers = 3;


    public static FireInspectionBuildingPositionFragment newInstance() {
        FireInspectionBuildingPositionFragment fragment = new FireInspectionBuildingPositionFragment();
        return fragment;
    }

    @Bind(R.id.recyclerView)
    RecyclerView mRecyclerView;

    private LemonRcvAdapter<CompanyBuildingItemCountVo> mAdapter;


    @Override
    protected void getBaseArguments() {
        if (getArguments() != null) {
            items = (List<CompanyBuildingItemCountVo>) getArguments().getSerializable(BundleKey.COMPANY_BUILDING_ITEM_COUNT);
            isSafeInspection = getArguments().getBoolean(BundleKey.IS_SAFE_INSPECTION, false);
        }
    }

    @Override
    protected int getContentViewId() {
        return R.layout.view_recycler_view;
    }

    @Override
    protected void initViews() {
        FullyGridLayoutManager gridLayoutManager = new FullyGridLayoutManager(getContext(), columnNumbers);
        gridLayoutManager.setOrientation(GridLayoutManager.VERTICAL);
        gridLayoutManager.setSmoothScrollbarEnabled(true);
        mRecyclerView.setLayoutManager(gridLayoutManager);
        mRecyclerView.setNestedScrollingEnabled(false);

        int spacingInPixels = getResources().getDimensionPixelSize(R.dimen.item_grid_divider_line);
        mRecyclerView.addItemDecoration(new SpacesItemDecoration(spacingInPixels));


        if (isSafeInspection) {
            mAdapter = new BuildingPositionForInspectionAdapter(items);
        }else{
            mAdapter = new BuildingPositionAdapter(items);
        }
        mRecyclerView.setAdapter(mAdapter);
    }


    @Override
    public void onDestroy() {
        super.onDestroy();

/*
        BuildingPositionRefreshEvent refreshEvent=new BuildingPositionRefreshEvent();
        refreshEvent.setTag(BuildingPositionRefreshEvent.class.getName());
        AppService.getBus().post(refreshEvent);
*/

    }
}
